package zdyu.data_structures.hash_map;

import org.junit.jupiter.api.Test;

import java.util.Random;
import java.util.stream.IntStream;

import static org.junit.jupiter.api.Assertions.*;

class HashMapTest {

    HashMap<String, Integer> hashMap = new HashMap<>();
    Random random = new Random();

    {
        IntStream.range(0, 5).forEach(i -> hashMap.put(String.valueOf(i), random.nextInt()));
    }

    @Test
    void containsKey() {
        System.out.println(hashMap.containsKey(""));
        System.out.println(hashMap.containsKey("1"));
        System.out.println(hashMap.containsKey(null));
        hashMap.put(null, 0);
        System.out.println(hashMap.containsKey(null));
    }

    @Test
    void containsValue() {
        System.out.println(hashMap.containsValue(null));
        System.out.println(hashMap.containsValue(0));
        hashMap.put("0", 0);
        System.out.println(hashMap.containsValue(0));
    }

    @Test
    void get() {
        System.out.println(hashMap);
        IntStream.range(-1, 5).forEachOrdered(i -> System.out.println(hashMap.get(String.valueOf(i))));
    }

    @Test
    void put() {
        System.out.println(hashMap);

        IntStream.range(0, 5).forEach(i -> hashMap.put(String.valueOf(i), random.nextInt()));
        System.out.println(hashMap);

        IntStream.range(0, 10).forEach(i -> hashMap.put(String.valueOf(i), null));
        System.out.println(hashMap);

        IntStream.range(0, 100).forEach(i -> hashMap.put(String.valueOf(i), random.nextInt()));
        System.out.println(hashMap);
        System.out.println(hashMap.getLoad());
    }

    @Test
    void remove() {
        System.out.println(hashMap.remove("0"));
        System.out.println(hashMap);
        System.out.println(hashMap.remove(""));
        System.out.println(hashMap);
    }

    @Test
    void clear() {
        hashMap.clear();
        System.out.println(hashMap);
        System.out.println(hashMap.size());
    }

    @Test
    void keySet() {
        hashMap.keySet().forEach((System.out::println));
    }

    @Test
    void values() {
        hashMap.values().forEach((System.out::println));
    }

    @Test
    void entrySet() {
        hashMap.entrySet().forEach((System.out::println));
    }
}